﻿using System.Diagnostics.Contracts;

namespace O1.Kernel.IO.Storage
{
    [ContractVerification(true)]
    internal class LinkingTask : DataTask<Linkage>
    {
        public LinkingTask(
            TransactionToken token,
            Linkage item, 
            int linkedId,
            DmlOperation operation,
            int targetId, 
            bool linkPrevious, 
            int linkOffset)
            : base(token, item, operation)
        {
            Contract.Requires(token != null);
            Contract.Requires(linkedId >= 0);
            Contract.Requires(targetId >= 0);
            Contract.Requires(linkOffset >= 0);

            this.TargetId = targetId;
            this.LinkPrevious = linkPrevious;
            this.LinkOffset = linkOffset;
            this.LinkedId = linkedId;
        }

        public bool LinkPrevious { get; private set; }

        public int LinkOffset { get; private set; }

        public int LinkedId { get; private set; }

        [ContractInvariantMethod]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
        private void ObjectInvariant()
        {
            Contract.Invariant(this.LinkedId >= 0);
            Contract.Invariant(this.TargetId >= 0);
            Contract.Invariant(this.LinkOffset >= 0);
        }
    }
}
